package com.imelite.qyh.data.util;

import com.alibaba.fastjson.JSON;
import com.imelite.qyh.data.JxcpcsAccessBean;
import com.imelite.qyh.data.JxcpcsAccessPageBean;
import com.imelite.qyh.enums.JxcpYMFZEnum;
import com.imelite.qyh.model.Jxcpcs;
import com.imelite.qyh.model.Jxcpcsfz;
import com.imelite.qyh.util.BaseStringUtil;

import java.util.ArrayList;
import java.util.List;

public class Jxcpcs_Util {

    public static JxcpcsAccessPageBean getBean(String[] ids, List<Jxcpcsfz> jxcpcsfzList, List<Jxcpcs> jxcpcsList){
        JxcpcsAccessPageBean jxcpcsAccessPageBean=new JxcpcsAccessPageBean();
        jxcpcsAccessPageBean.setDxlist_JBXX(getFZ(ids,JxcpYMFZEnum.JBXX.getLabel(),jxcpcsList,jxcpcsfzList));//获得基本信息
        jxcpcsAccessPageBean.setDxlist_XLTZ(getdxList(ids,JxcpYMFZEnum.XLTZ.getLabel(),jxcpcsList,jxcpcsfzList));//您的心理与性格特征
        jxcpcsAccessPageBean.setGNSK_yh(yxz(ids,getdxList(ids,JxcpYMFZEnum.GNSK.getLabel(),jxcpcsList,jxcpcsfzList)));//您的感觉-思考-行动 观察 类型 用户选择项
        jxcpcsAccessPageBean.setSJTJ_yh(yxz(ids,getdxList(ids,JxcpYMFZEnum.SJTJ.getLabel(),jxcpcsList,jxcpcsfzList)));//您的 视觉 听觉 动觉 类型 用户选择项

        List<JxcpcsAccessBean> jxcpcsAccessBeanList_GNSK=getLDT(ids,JxcpYMFZEnum.GNSK.getLabel(),jxcpcsList,jxcpcsfzList);//您的感觉-思考-行动 观察 类型
        jxcpcsAccessPageBean.setGNSK_list(jxcpcsAccessBeanList_GNSK);
        jxcpcsAccessPageBean.setGNSK_JSON(JSON.toJSONString(jxcpcsAccessBeanList_GNSK));
        List<JxcpcsAccessBean> jxcpcsAccessBeanList_SJTJ=getLDT(ids,JxcpYMFZEnum.SJTJ.getLabel(),jxcpcsList,jxcpcsfzList);//您的 视觉 听觉 动觉 类型
        jxcpcsAccessPageBean.setSJTJ_list(jxcpcsAccessBeanList_SJTJ);
        jxcpcsAccessPageBean.setSJTJ_JSON(JSON.toJSONString(jxcpcsAccessBeanList_SJTJ));
        return jxcpcsAccessPageBean;
    }



    //获得基本信息
    private static List<Jxcpcs> getFZ(String[] ids,String fzid,List<Jxcpcs> jxcpcsList,List<Jxcpcsfz> jxcpcsfzList){
        List<Jxcpcs> temp=new ArrayList<>();
        for(Jxcpcsfz j:jxcpcsfzList){
            if(BaseStringUtil.isNotBlank(j.getYmfz())&&j.getYmfz().equals(fzid)){
                for(Jxcpcs cs:jxcpcsList){
                    if(BaseStringUtil.isNotBlank(cs.getFz())&&cs.getFz().equals(j.getId())&&sfbh(ids,cs.getId())){
                        temp.add(cs);
                    }
                }
            }
        }

        return temp;
    }


    private static List<JxcpcsAccessBean> getLDT(String[] ids,String fzid,List<Jxcpcs> jxcpcsList,List<Jxcpcsfz> jxcpcsfzList){
        List<Jxcpcsfz> temp=new ArrayList<>();
        for(Jxcpcsfz j:jxcpcsfzList){
            if(BaseStringUtil.isNotBlank(j.getYmfz())&&j.getYmfz().equals(fzid)){
                temp.add(j);
            }
        }

        List<JxcpcsAccessBean> jxcpcsAccessBeanList=new ArrayList<>();

        for(Jxcpcsfz j:temp){
            JxcpcsAccessBean jxcpcsAccessBean=new JxcpcsAccessBean();
            jxcpcsAccessBean.setFzid(j.getId());
            jxcpcsAccessBean.setSname(j.getSname());
            jxcpcsAccessBean.setBz(j.getBz());
            int num=0;
            for(Jxcpcs cs:jxcpcsList){
                if(BaseStringUtil.isNotBlank(cs.getFz())&&cs.getFz().equals(j.getId())&&sfbh(ids,cs.getId())){
                    num++;
                }
            }
            jxcpcsAccessBean.setNum(num);
            jxcpcsAccessBeanList.add(jxcpcsAccessBean);
        }
        return jxcpcsAccessBeanList;
    }


    //获得心里特征
    private static List<Jxcpcs> getdxList(String[] ids,String fzid,List<Jxcpcs> jxcpcsList,List<Jxcpcsfz> jxcpcsfzList){
        List<Jxcpcs> temp=new ArrayList<>();
        for(Jxcpcsfz j:jxcpcsfzList){
            if(BaseStringUtil.isNotBlank(j.getYmfz())&&j.getYmfz().equals(fzid)){
                for(Jxcpcs cs:jxcpcsList){
                    if(BaseStringUtil.isNotBlank(cs.getFz())&&cs.getFz().equals(j.getId())){
                        temp.add(cs);
                    }
                }
            }
        }

        for(Jxcpcs j:temp){
            if(j.getSffz()==0){
                if(sfbh(ids,j.getId())){
                    j.setAccessMsg(j.getYes());
                    j.setSfxz(true);
                }else{
                    j.setAccessMsg(j.getNo());
                    j.setSfxz(false);
                }
            }
        }
        return temp;
    }

    //获得已选择的内容
    private static List<Jxcpcs> yxz(String[] ids,List<Jxcpcs> jxcpcsList){
        List<Jxcpcs> temp=new ArrayList<>();
        for(Jxcpcs j:jxcpcsList){
            if(sfbh(ids,j.getId())){
                temp.add(j);
            }
        }
        return temp;
    }

    private static boolean sfbh(String[] ids,String id){
        for(String s:ids){
            if(s.equals(id)){
                return true;
            }
        }
        return false;
    }
}
